package cn.anecansaitin.industrialization_expansion.client.event;

import cn.anecansaitin.industrialization_expansion.ExtensionLoader;
import cn.anecansaitin.industrialization_expansion.ModConstant;
import cn.anecansaitin.industrialization_expansion.client.ClientEventHooks;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = ModConstant.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class OnModelRegistry {
    @SubscribeEvent
    public static void modelRegistryEvent(ModelRegistryEvent event) {
        loadDefaultModel();
        ClientEventHooks.fireCustomModelRegisterEvent();
        ExtensionLoader.MODEL_IDS.forEach(s -> ModelLoader.addSpecialModel(getModelPath(s)));
    }

    private static ResourceLocation getModelPath(String name) {
        return new ModelResourceLocation(ModConstant.MOD_ID + ":" + name, "inventory");
    }

    private static void loadDefaultModel() {
        ModelLoader.addSpecialModel(getModelPath("miss"));
        ModelLoader.addSpecialModel(getModelPath("tool_axe_head"));
        ModelLoader.addSpecialModel(getModelPath("item_axe_head"));
        ModelLoader.addSpecialModel(getModelPath("tool_balancer"));
        ModelLoader.addSpecialModel(getModelPath("item_balancer"));
        ModelLoader.addSpecialModel(getModelPath("tool_handle"));
        ModelLoader.addSpecialModel(getModelPath("item_handle"));
        ModelLoader.addSpecialModel(getModelPath("tool_hoe_head"));
        ModelLoader.addSpecialModel(getModelPath("item_hoe_head"));
        ModelLoader.addSpecialModel(getModelPath("tool_pickaxe_head"));
        ModelLoader.addSpecialModel(getModelPath("item_pickaxe_head"));
        ModelLoader.addSpecialModel(getModelPath("tool_shovel_head"));
        ModelLoader.addSpecialModel(getModelPath("item_shovel_head"));
        ModelLoader.addSpecialModel(getModelPath("tool_axe_handle"));
        ModelLoader.addSpecialModel(getModelPath("item_screwdriver_handle"));
        ModelLoader.addSpecialModel(getModelPath("tool_screwdriver_handle"));
        ModelLoader.addSpecialModel(getModelPath("item_screwdriver_head"));
        ModelLoader.addSpecialModel(getModelPath("tool_screwdriver_head"));
        ModelLoader.addSpecialModel(getModelPath("item_wrench_head"));
        ModelLoader.addSpecialModel(getModelPath("tool_wrench_head"));
        ModelLoader.addSpecialModel(getModelPath("tool_wrench_handle"));
        ModelLoader.addSpecialModel(getModelPath("item_crowbar_bar"));
        ModelLoader.addSpecialModel(getModelPath("tool_crowbar_bar"));
        ModelLoader.addSpecialModel(getModelPath("item_crowbar_sleeve"));
        ModelLoader.addSpecialModel(getModelPath("tool_crowbar_sleeve"));
        ModelLoader.addSpecialModel(getModelPath("item_hammer_head"));
        ModelLoader.addSpecialModel(getModelPath("tool_hammer_head"));
        ModelLoader.addSpecialModel(getModelPath("tool_hammer_handle"));

    }
}
